function PyResult(){
	this.form=this.InitForm();
    this.contrlInit();
	this.table=this.InitTableByBt();
}
PyResult.prototype.InitForm=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
	   form.render();
	});  
	return form;
}

PyResult.prototype.contrlInit = function() {
    var month =  $("#hidmonth").val();
    var select = 'dd[lay-value=' + month + ']';
    $('#month').siblings("div.layui-form-select").find('dl').find(select).click();

}

PyResult.prototype.InitTableByBt=function (){
	var table;
	var _this=this;
	layui.use('table', function() {
	    table = layui.table;
	    table.init('uatmzpdsummarylist', {
			height : $(window).height() - 100
			,url : 'get_workpay_list' // 数据接口
			,page : true // 开启分页
			,limit : 40
            ,limits:[20,40,80,100]
			,id: 'uatmzpdsummary'
			,method:"post"
				,request:{
					type:'post'
				}
				,where:{
                	year: $("#year").val(),
                    month:$("#month").val(),
                	orgid:$("#szdw").val(),
                status:$("#hidstatus").val()
					}
			    ,done: function(res, page, count){
					var year = $("#year").val();
					var month = $("#mouth").val();
					var orgname =$.trim($("#szdw").find("option:selected").text());
					$("#title").html(orgname+" "+year+" 年  "+month+" 月工作津贴表");
			    }
		  });
        //是否修改就是保存
	    // table.on('edit(test)', function(obj){
        //     console.log(obj.data); //所在行的所有相关数据
        // });
	})


	return table;
}

PyResult.prototype.save=function(){
    var tabledataJson = this.table.cache;
    var year = $("#year").val();
    var month = $("#month").val();
    tabledataJson['year']=year;
    tabledataJson['month']=month;
    tabledataJson = JSON.stringify(tabledataJson);
    tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g,'lay_TABLE_INDEX');
    console.log(tabledataJson);
    $.ajax({
        type:"POST",
        url:"work_pay_save",
        contentType: 'application/json',
        data:tabledataJson,
        beforeSend:function(XHR){

        },
        success:function(data){
            if(data>0){
                top.mylayui.msg("保存成功", {icon: 1});
                // document.location.reload();
                $("#refbutton").click();
            }
            else{
                top.mylayui.msg("保存失败", {icon: 0});
            }
        },
        complete:function(XHR){
            var res = XHR.responseText;
        },
        error:function(XHR,errorText,errorType){
            var res = XHR.responseText;
            top.mylayui.msg('操作失败', {icon: 0});
        }
    });
}

PyResult.prototype.searchtable=function(){
	this.table.reload('uatmzpdsummary', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	    ,where: {  
	    	year: $("#year").val(),
			month:$("#mouth").val(),
            orgid:$("#szdw").val(),
            status:$("#hidstatus").val()
	    }  
	}); 
}

PyResult.prototype.count=function(){
    this.table.reload('uatmzpdsummary', {
        where: {
            year: $("#year").val(),
            month:$("#mouth").val(),
            orgid:$("#szdw").val(),
            count:1
        }
    });
}

PyResult.prototype.tableref=function(){
    this.table.reload('uatmzpdsummary', {
        where: {
            year: $("#year").val(),
            month:$("#month").val(),
            orgid:$("#szdw").val(),
        }
    });
}

//导出excle
PyResult.prototype.excle=function(){

}

//归档&发布
PyResult.prototype.update=function(status){
    var tabledataJson = this.table.cache;
    var year = $("#year").val();
    var month = $("#month").val();
    tabledataJson['year']=year;
    tabledataJson['month']=month;
    tabledataJson['status']=status;
    tabledataJson = JSON.stringify(tabledataJson);
    tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g,'lay_TABLE_INDEX');

    $.ajax({
        type:"POST",
        url:"work_pay_update",
        contentType: 'application/json',
        data:tabledataJson,
        beforeSend:function(XHR){

        },
        success:function(data){
            if(data>0){
                top.mylayui.msg("更新成功！", {icon: 1});
                document.location.reload();
            }
            else{
                top.mylayui.msg("更新失败！", {icon: 0});
            }
        },
        complete:function(XHR){
        },
        error:function(XHR,errorText,errorType){
            var res = XHR.responseText;
            top.mylayui.msg('操作失败', {icon: 0});
        }
    });

}


var vWorkPayResult=null;
$(function(){
	vWorkPayResult=new PyResult();
})
